#!/bin/bash

set -e
shopt -s extglob

test=$1

case $test in
download/*) DISTDIR= ;;
*) DISTDIR=${top_srcdir}/testsuite/distdir ;;
esac

test -d ${top_builddir}/testsuite/$test || mkdir -p ${top_builddir}/testsuite/$test
cd ${top_builddir}/testsuite/$test

cp -f ${top_srcdir}/testsuite/$test/!(hints) .

DISTDIR=${DISTDIR} ${top_builddir}/bin/cygport-inplace *.cygport clean get all

# compare hints
for hint in $(find -name \*.hint)
do
    if [ -a ${top_srcdir}/testsuite/$test/hints/$hint ];
    then
        diff -u ${top_srcdir}/testsuite/$test/hints/$hint $hint
# uncomment to create the expected hint file for use in future testing
#    else
#        mkdir -p $(dirname ${top_srcdir}/testsuite/$test/hints/$hint)
#        cp $hint ${top_srcdir}/testsuite/$test/hints/$hint
    fi
done

# compare filelist
diff -u ${CASE_INSENSITIVE:+-i} ${top_srcdir}/testsuite/$test/*.list <(${top_builddir}/bin/cygport-inplace *.cygport list)
